set hive.exec.dynamic.partition=true;            --  动态分区
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions=500;         --  每天生成 60 个分区
set hive.exec.max.dynamic.partitions.pernode=500; --  每天生成 60 个分区
insert overwrite table jms_dm.dm_cus_active_laxin2v_volume_cnt_dt
select
     date_add('{{ execution_date | cst_ds }}',0) as input_time
     ,t2.customer_code
     ,max(t1.customer_name) as customer_name
     ,sum(if(t1.input_time='{{ execution_date | cst_ds }}',t1.waybill_cnt,0)) as waybill_cnt
     ,sum(if(t1.input_time between t2.create_date and'{{ execution_date | cst_ds }}' , waybill_cnt,0)) as acc_waybill_cnt
     ,t2.inviter_code
     ,'{{ execution_date | cst_ds }}' as  date_time
     ,'{{ execution_date | cst_ds }}' as  dt
from
    (
        select
            customer_code
             ,max(customer_name) customer_name
             ,count(waybill_no) as  waybill_cnt
             ,date(input_time) as input_time
    from jms_dwd.dwd_yl_oms_oms_waybill_incre_dt
    where dt between '2023-07-17'  and '{{ execution_date | cst_ds }}'
    group by customer_code,date(input_time)
    )t1 right join
    (
         select
             customer_code
                 ,date(create_time) as create_date
                 ,if(is_inviter=1 and inviter is not null,inviter,null) as inviter_code
         from jms_dwd.dwd_yl_new_customer_activity_sp_base
         where status=1 --满足条件的客户
          and  market_activity_code='J00002' --新活动编码
    )t2 on t1.customer_code=t2.customer_code
group by t2.customer_code,t2.inviter_code
distribute by 1;